package com.canqiang.template;

import java.util.List;

import com.canqiang.docadvice.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class DealNoteAdapter extends ArrayAdapter<DealNote>{
	private LayoutInflater mInflater;
	public DealNoteAdapter(Context context, int textViewResourceId,
			List<DealNote> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.mInflater = LayoutInflater.from(context);
	}
	@Override  
    public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){ 
			convertView= mInflater.inflate(R.layout.dealnoteview,null);
		}
		DNholder holder=null;
		final DealNote dealnote=getItem(position);
		if(holder==null){
        	holder = new DNholder();
        	holder.active=(TextView) convertView.findViewById(R.tpl.dealactive);
        	//holder.no=(TextView) convertView.findViewById(R.tpl.dealno);
        	holder.name=(TextView) convertView.findViewById(R.tpl.dealname);
        	holder.type=(TextView) convertView.findViewById(R.tpl.dealtype);
        	holder.number=(TextView) convertView.findViewById(R.tpl.dealnumber);
        	holder.dose=(TextView) convertView.findViewById(R.tpl.dealdose);
        	holder.unit=(TextView) convertView.findViewById(R.tpl.dealunit);
        	//holder.group=(TextView) convertView.findViewById(R.tpl.dealgroup);
        	holder.use=(TextView) convertView.findViewById(R.tpl.dealuse);
        	holder.kind=(TextView) convertView.findViewById(R.tpl.dealkind);
        	//holder.pricekind=(TextView) convertView.findViewById(R.tpl.pricekind);
        	holder.state=(CheckBox) convertView.findViewById(R.tpl.dealcheck);
        	holder.state.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					CheckBox cb = (CheckBox)v;
					//cb.toggle();
					dealnote.setState(cb.isChecked());
				}
        		
        	});
        	convertView.setTag(holder);
		}
		else{
			holder=(DNholder) convertView.getTag();
		}
		holder.active.setText(dealnote.getActive());
		//holder.no.setText(dealnote.getDealno());
		holder.name.setText(dealnote.getDealname());
		holder.type.setText(dealnote.getDealtype());
		holder.number.setText(dealnote.getDealnumber());
		holder.dose.setText(dealnote.getDealdose());
		holder.unit.setText(dealnote.getDoseunit());
		//holder.group.setText(dealnote.getDealgroup());
		holder.use.setText(dealnote.getDealuse());
		holder.kind.setText(dealnote.getKind());
		//holder.pricekind.setText(dealnote.getPricekind());
		holder.state.setChecked(dealnote.getState());
		return convertView;
	}
	private static class DNholder{
		CheckBox state;
		TextView active;
		//TextView no;
		TextView name;
		TextView type;
		TextView number;
		TextView dose;
		TextView unit;
		//TextView group;
		TextView use;
		TextView kind;
		//TextView pricekind;
	}

}

